package cn.doitedu.rest.call;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class AtlasApiCallDemo {
    public static void main(String[] args) throws IOException {


        // 构造用户名密码鉴权对象
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
        BasicCredentialsProvider provider = new BasicCredentialsProvider();
        provider.setCredentials(AuthScope.ANY,credentials);

        //构造httpclient的实例
        HttpClientBuilder builder = HttpClientBuilder.create();
        builder.setDefaultCredentialsProvider(provider);
        CloseableHttpClient client = builder.build();

        // 构造get请求
        HttpGet get = new HttpGet("http://doitedu01:21000/api/atlas/v2/search/basic?typeName=hive_table&query=app*");

        // 用httpclient实例去发送这个请求
        CloseableHttpResponse response = client.execute(get);


        // 获取请求的响应数据
        String result = EntityUtils.toString(response.getEntity());

        // 解析数据
        System.out.println(result);

        client.close();




    }
}
